<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link th:href="@{/css/style.css}" rel="stylesheet" type="text/css" />
  <script type="text/javascript" th:src="@{/js/jquery.js}"></script>
</head>

<body>
<div class="place"> <span>位置：</span>
  <ul class="placeul">
    <li>仓库管理</li>
    <li><a href="/erp/rep/ware/allWare">仓库管理</a></li>
    <li>添加仓库</li>
  </ul>
</div>
<div class="formbody">
  <div class="formtitle"><span>仓库信息</span></div>

    <form action="/erp1/rep/ware/doadd" method="post" id="addfrom">

      <span th:text="${msg}" style="color: red"></span>
  <ul class="forminfo">
    <li>
      <label>仓库名称</label>
      <input name="cName" type="text" class="dfinput" id="cName"/>
      <i>必填，不能超过30个字符</i>
    </li>
    <li>
      <label>仓库地址</label>
      <input name="cAddress" type="text" class="dfinput" id="cAddress" />
      <i>必填，不能超过300个字符</i>
    </li>
    <li>
      <label>所属区域</label>
      <select class="dfselect" name="provinceId" onchange="getCity(this.value)" id="provinceId">
          <option value="0">请选择</option>
          <option th:each="p : ${session.provinces}" th:value="${p.id}" th:text="${p.pName}"></option>
      </select>
      省
      <select class="dfselect" name="cityId" id="cityId">
          <option value="0">请选择</option>
      </select>
      市
      <i>必选</i>
    </li>
    <li>
      <label>负责人</label>
      <select class="dfselect" name="usreId" id="usreId">
          <option value="0">请选择</option>
          <option th:each="u : ${cwUsers}" th:value="${u.uId}" th:text="${u.uname}"></option>
      </select>
       <i>只能是财务部或仓库管理员职位</i>
    </li>
    <li>
      <label>联系方式</label>
      <input name="phone" type="text" class="dfinput" id="phone" />
       <i>必填，不能超过30个字符</i>
    </li>
    <li>
      <label>描述</label>
      <textarea class="textinput" name="details"></textarea>
      <i>可选</i>
    </li>
    <li>
      <label>状态</label>
      <select class="dfselect" name="state" id="state">
          <option value="1">可用</option>
          <option value="2">不可用</option>
        </select>
      <i>必选</i>
    </li>
    <li>
      <label>创建人</label>
        <input type="hidden" name="usersId" th:value="${session.currUser.uId}"/>
      <input type="text" th:value="${session.currUser.uname}" readonly="readonly" class="roinput" />
      <i>不能编辑</i>
    </li>
    <li>
      <label>创建时间</label>
      <input name="creationTime" type="text" th:value="${#dates.format(new java.util.Date().getTime(), 'yyyy-MM-dd HH:mm:ss')}" readonly="readonly" class="roinput" />
      <i>不能编辑</i>
    </li>
    <li>
      <label>&nbsp;</label>
      <input onclick="addWarehouse()" type="button" class="btn" value="确定"/>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <input type="button" class="btn" value="返回" onclick="window.history.go(-1)"/>
    </li>
  </ul>
    </form>
</div>

<script type="text/javascript">
  //简单验证
  $(function () {
    $("#cName").blur(function () {
      warecName();
    });
    $("#cAddress").blur(function () {
      warecAddress();
    });
    $("#provinceId").blur(function () {
      wareprovinceId();
    });
    $("#cityId").blur(function () {
      warecityId();
    });
    $("#usreId").blur(function () {
      wareusreId();
    });
    $("#phone").blur(function () {
      warephone();
    });
  });

  function warecName() {
    if($("#cName").val()==""){
      return false;
    }else{
      return true;
    }
  }
  function warecAddress() {
    if($("#cAddress").val()==""){
      return false;
    }else{
      return true;
    }
  }
  function wareprovinceId() {
    if($("#provinceId").val()==""){
      return false;
    }else{
      return true;
    }
  }
  function warecityId() {
    if($("#cityId").val()==""){
      return false;
    }else{
      return true;
    }
  }
  function wareusreId() {
    if($("#usreId").val()==""){
      return false;
    }else{
      return true;
    }
  }
  function warephone() {
    if($("#phone").val()==""){
      return false;
    }else{
      return true;
    }
  }
  function addWarehouse() {
    if(warecName()&&warecAddress()&&wareprovinceId()&&warecityId()&&wareusreId()&&warephone()){
      $("#addfrom").submit();
    }else{
      confirm("添加仓库失败，请检查是否漏填或格式错误！");
    }
  }

  function getCity(num) {
    $.get("/erp1/ajaxCity", {"pid": num}, function (data) {
      $("select[name=cityId]").html("");
      var options = "<option value='0'>请选择</option>"
      $.each(data, function (i, e) {
        options += "<option value=" + e.id + ">" + e.cname + "</option>"
      })
      $("select[name=cityId]").append(options);
    }, "json");
  }
</script>
</body>
</html>
